//
//  CancellationByPWVC.m
//  NtoccShipper
//
//  Created by mac on 2020/1/10.
//  Copyright © 2020 zhuchongjin. All rights reserved.
//

#import "CancellationByPWVC.h"
#import "CancellationByCodeVC.h"
#import "LogInVC.h"
@interface CancellationByPWVC ()
@property (strong, nonatomic) CJButton *btnSave;
@property (nonatomic,strong) CJButton *btnAnother;
@end

@implementation CancellationByPWVC

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view from its nib.
    [self setTitleName:CJLString(@"验证中心")];
    [self setBackLeftButton:@""];
    [self createUI];
    [self.view addSubview:self.btnSave];
}

- (void)createUI{
    
    NSArray *list = @[@"请填写登录密码",@""];
    for (int i = 0; i < list.count; i++) {
        
        UIView * liebiaoView = [[UIView alloc]initWithFrame:CGRectMake(0,kTopHeight + CJToViewMarginH+ i * 44, kScreenWidth, 44)];
        liebiaoView.backgroundColor = [UIColor cjWhiteColor];
        [self.view addSubview:liebiaoView];

        if (i == 0) {
            CJTextField *field = CJTextField.tfInit
            .tfFrame(CGRectMake( CJToLeftMargin, 5, kScreenWidth - 2*CJToLeftMargin - 60, 35))
            .tfplaceholder(list[i])
            ;
            field.tag = 1000+ i;
            [liebiaoView addSubview:field];
        }else{
            
            self.btnAnother = CJButton.btnInit
            .btnFrame(CGRectMake(kScreenWidth - 100 - CJToLeftMargin, LW(10), LW(100), liebiaoView.height - LW(20)))
//            .btnBgColor([UIColor cjMainColor])
            .btnNormalTitleColor([UIColor cjMainColor])
            .btnTargetAction(self,@selector(btnAnotherAction:))
            .btnCornerRadius(3)
            .btnText(@"切换验证方式")
            ;
            [liebiaoView addSubview:self.btnAnother];
        }
        
        UILabel * bg = [[UILabel alloc]initWithFrame:CGRectMake(CJToLeftMargin, liebiaoView.height -1, SCREEN_WIDTH, 1)];
        bg.backgroundColor = [UIColor cjBackgroundColor];
        [liebiaoView addSubview:bg];
    }
}

- (void)btnAnotherAction:(UIButton *)sender{
    CancellationByCodeVC *vc = [CancellationByCodeVC new];
    vc.strPhoneNum = self.strPhoneNum;
    [self pushVc:vc];
}

- (void)btnSaveAction{
    
    UITextField *filed1 = [self.view viewWithTag:1000];
    if ([CJRegular getIsStrEmpty:filed1.text]) {
        [CJAlert showStringDismissWithDelay:@"密码不能为空"];
        return;
    }
    
    NSString *strURL = CJStringWithFormat(@"%@/ntocc-basic-api/party/confirmBye",CJBaseUrl);
    NSDictionary *dicPar = @{@"type":@"passwd",
                             @"passwd":[CJControl base64:filed1.text],
    };
    
    @weakify(self);
    [[HDNetworking sharedHDNetworking] DELETE:strURL parameters:dicPar success:^(id  _Nonnull responseObject) {
        
        @strongify(self);
        [CJControl clearAllUserDefaultsData];
//        DLog(@"++++++++%@",responseObject);
        LogInVC *vc = [[LogInVC alloc]init];
        vc.isRegsiter = YES;
        [self pushVc:vc];
       
    } failure:^(NSError * _Nonnull error) {
//        DLog(@"++++++++%@",error);
    }];

}
#pragma mark ----------lazy

- (CJButton *)btnSave{
    if (!_btnSave) {
        _btnSave = CJButton.btnInit
        .btnFrame(CGRectMake(1*CJToLeftMargin, kTopHeight +  LW(140), SCREEN_WIDTH - 2*CJToLeftMargin, LW(40)))
        .btnFont([UIFont cjTitleFont17])
        .btnText(@"确认")
        .btnBgColor([UIColor cjMainColor])
        .btnCornerRadius(5)
        .btnNormalTitleColor([UIColor cjWhiteColor])
        .btnTargetAction(self, @selector(btnSaveAction))
        ;
    }
    return _btnSave;
}













@end
